// Encoder.h: interface for the CEncoder class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ENCODER_H__682D0394_1B0A_448C_90F8_DFBA70548D83__INCLUDED_)
#define AFX_ENCODER_H__682D0394_1B0A_448C_90F8_DFBA70548D83__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CEncoder  
{
public:
	HRESULT Read( void *pv,ULONG cb,ULONG *pcbRead);
	void closeCurrentStream();
	void put_stream(IStream * pStream);
	CEncoder();
	virtual ~CEncoder();

	//inserts a character into the pending block, 
	//	writes it to the stream if large enough,
	//	handles writing of linebreaks and maintaining
	//	position counters..
	void putc(char c);

	//TODO:
	//governs whether to write characters to the stream
	//	as bytes or widechars (notimpl) 
	bool m_bWideOutput;

private:
	char * m_pcMatrix;
	
	// current position since last crlf or bof
	int m_iLinePos;
	
	// current position in input block
	short m_sBlockPos;

	// input block
	char m_inputBlock[3];

	//encodes the block-of-three and writes it to the stream
	void encodeblock(const short len );

	//holds the stream to which encoded data is being written.
	//	probably move to base class
	
	//TODO: figure out how to do this in a standard way, 
	//	eg. use a callback.
	//	This should be able to be any kind of stream,
	//	not just a COM one.
	IStream * m_pTargetStream;
	//clone of the targetStream, used for reading.
	IStream * m_pReadStream;
	

	// constant values for encoding
		//maximum size of unencoded block
		const short m_sBlockSize;	
		//maximum distance between crlf
		const int m_iMaxLineSize;


};

#endif // !defined(AFX_ENCODER_H__682D0394_1B0A_448C_90F8_DFBA70548D83__INCLUDED_)
